// custom-tab-bar/index.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    active: 0,
    tabs: [
      {
        url: "/pages/index/index",
        iconNormal: "icon-dushu-normal",
        iconActive:"icon-dushu-active",
        text: "领读"
      },
      {
        url: "/pages/categroy/categroy",
        iconNormal: "icon-cate-normal",
        iconActive:"icon-cate-active",
        text: "分类"
      },
      {
        url: "/pages/desk/desk",
        iconNormal: "icon-shuzhuo-normal",
        iconActive:"icon-shuzhuo-active",
        text: "书桌"
      },
      {
        url: "/pages/mine/mine",
        iconNormal: "icon-mine-normal",
        iconActive:"icon-mine-active",
        text: "我的"
      }
    ]
  },

  /**
   * 组件的方法列表
   */
  methods: {
    tabChange(ev){
      this.setData({
        active:ev.detail
      })
      wx.switchTab({
        url: this.data.tabs[ev.detail].url,
      })
    },
    init(){
      const page = getCurrentPages().pop()
      this.setData({
        active:this.data.tabs.findIndex(v => v.url === '/' + page.route)
      })
    }
  }
})
